package org.melanesia.converters.jdbc;

import java.sql.Statement;
import java.sql.Types;

import org.melanesia.converters.JavaToJdbcConverter;
import org.melanesia.converters.TypeConverter;
import org.melanesia.converters.exceptions.ConversionException;
import org.melanesia.converters.java.DateToDateConverter;

/**
 * Converts date types into {@link java.sql.Timestamp} for passing inside the
 * JDBC.
 *
 * @author marcin.kielar
 */
public class DateToJdbcConverter extends JavaToJdbcConverter {

    /**
     * Internal dates converter.
     */
	private final DateToDateConverter dataToDateConverter = new DateToDateConverter(java.sql.Timestamp.class);

    @Override
    public final int getJdbcType(final TypeConverter typeConverterContext) {
        return Types.TIMESTAMP;
    }

    @Override
    public final Object convert(final TypeConverter typeConverterContext, final Object value, final Statement stmt,
            final String parameterName) throws ConversionException {
        return dataToDateConverter.convert(typeConverterContext, value);
    }
}
